<?php
/**
 * Created by PhpStorm.
 * User: jinqiang
 * Date: 2021/4/29
 * Time: 11:14
 */

namespace App\Http\Models\Mysql;


use Illuminate\Database\Eloquent\Model;

class Base extends Model
{
    protected $primaryKey = 'id';

    public $timestamps = false;

    protected $hidden = [];

    public $guarded = [];

    public $connection = 'mysql';

    public function createData($data)
    {
        try {
            $res = $this->create($data);
            if ($res) {
                return ['code' => 0, 'msg' => '提示：操作成功', 'id' => $res->id];
            }
        } catch (\Exception $e) {
            return ['code' => -1, 'msg' => $e->getMessage()];
        }
        return ['code' => 0, 'msg'=>'提示：插入成功'];
    }

    public function updateData($id, $data)
    {
        try{
            $this->where('id', $id)->update($data);
            return ['code' => 0, 'msg' => '提示：更新成功'];
        }catch (\Exception $e){
            return ['code' => -1, 'msg' => $e->getMessage()];
        }
    }

    public function deleteData($id)
    {
        try{
            $this->where('id', $id)->delete();
            return ['code' => 0, 'msg' => '提示：删除成功'];
        }catch (\Exception $e){
            return ['code' => -1, 'msg' => $e->getMessage()];
        }
    }
}
